<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax</title>
</head>
<body>
<form autocomplete="off">
    姓名：<input type="text" id="username">
    <span id="uSpan"></span>
    <br>
    密码：<input type="password" id="password">
    <br>
    <input type="submit" value="注册">
</form>
</body>
        <script src="js/jquery-3.3.1.min.js"></script>
            <script>
                $("#username").blur(function (){
                   let val = $("#username").val();
                   $.ajax({
                      url:"userServlet",
                       async:true,
                       data:"username="+val,
                       type:"post",
                       dataType:"text",
                       success:function (data){
                          $("#uSpan").html(data);
                       },
                        error:function (){
                            alert("哈哈哈，弄错了吧！！");
                        },
                   });
                });




     /*              $("#username").blur(function (){
                     let val = $("#username").val();
                     //1.首先方法 注意里面要有{}
                       $.ajax({
                           //1.1路径
                           url:"userServlet",
                           //1.2参数
                           data:"username="+val,
                           //1.3方式
                           type:"POST",
                           //1.4数据类型
                            dataType:"text",
                           //1.5成功
                            success:function (data){
                               $("#uSpan").html(data);
                            },
                           //1.6失败
                            error:function (){
                               alert("你的操作有问题---");
                            }
                       });
                   });*/
            </script>
</html>